package sourceCodeAnalysis.CGLIB;

import net.sf.cglib.core.DebuggingClassWriter;
import net.sf.cglib.proxy.Enhancer;

public class CglibProxyTest {
    public static void main(String[] args) {
        //首先是创建一个net.sf.cglib.proxy.Enhancer对象
        Enhancer enhancer = new Enhancer();
        //然后调用setSuperclass()方法 将enhancer对象的父类设置为Coder类：
        enhancer.setSuperclass(Coder.class);
        //紧接着调用了setCallback()方法将enhancer对象的方法拦截器设置为自定义的AttendanceMethodInterceptor
        enhancer.setCallback(new AttendanceMethodInterceptor());

        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "./cglib");

        // 创建代理对象
        Object object = enhancer.create();

        Coder coder = (Coder) object;
        int work = coder.work(1);
        System.out.println(work);
    }
}
